package com.zlm.tools;

import com.zlm.tools.util.ExceptionUtil;

/**
 * 十个位移运算
 *
 * @author zlm
 * @date 2023/8/5
 */
public class TenDisplacement {

    public static void main(String[] args) {
        //乘以2
        int num = 10 << 1;
        System.out.println(num);
        //快速计算2的n次幂
        int x = 1 << 10;
        System.out.println(x);
        //校验奇偶数
        int number = 11;
        if((number & 1) == 0){
            System.out.println("偶数");
        }else{
            System.out.println("奇数");
        }
        //交互两个变量
        int a = 1;
        int b = 2;
        a ^= b;
        b ^= a;
        a ^= b;
        System.out.println(a +" : "+b);

        //找出只出现一次的数
        Integer[] arr = new Integer[]{12,12,14,14,15};
        Integer[] res = new Integer[1];
        res[0] = 0;
        for (int i = 0; i < arr.length; i++) {
            res[0] ^= arr[i];
        }
        System.out.println(res[0]);

        //对数字加密
        int s = 1234567;
        int key = 6432;
        int encrypt = s ^ key;
        System.out.println("密文: "+encrypt);
        System.out.println("解密: "+(encrypt^key));

    }

}
